﻿#include <iostream>
#include <string>
#include <thread>

#include <zmq.hpp>

#include "../../inc/helper.hpp"

int main()
{
	zmq::context_t ctx;
	zmq::socket_t frontend(ctx, zmq::socket_type::router);
	zmq::socket_t backend(ctx, zmq::socket_type::dealer);
	frontend.bind("tcp://*:5559");
	backend.bind("tcp://*:5560");

	std::vector<zmq::pollitem_t> items = {
		{frontend, 0, ZMQ_POLLIN, 0},
		{backend, 0, ZMQ_POLLIN, 0}
	};

	while (true) {
		zmq::poll(items);

		zmq::message_t msg;
		if (items[0].revents & ZMQ_POLLIN)
		{
			info("msg from frontend");
			frontend.recv(&msg);
			backend.send(msg, msg.more() ? ZMQ_SNDMORE : 0);
		}
		else if(items[1].revents & ZMQ_POLLIN)
		{
			info("msg from backend");
			backend.recv(&msg);
			frontend.send(msg, msg.more() ? ZMQ_SNDMORE : 0);
		}
	}
}
